﻿using FPSO.Models.Constant;
using FPSO.Models.ViewModel.TaskManage;
using Org.BouncyCastle.Utilities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace FPSO.Models.Domain
{
    public class TankCalcState
	{
		public string Abname { get; set; }
		public double Weight { get; set; }
        public double Density { get; set; }
        public double Inn { get; set; }
        public double Volume { get; set; }
		private double _full;
		public double Full 
		{
			get => _full;
			set
			{
				if (_full != value)
				{
					_full = value;
					ModIVFWD(Abname, "Full", _full);
				}
			}
		}

		public double LCG { get; set; }
        public double TCG { get; set; }
        public double VCG { get; set; }
        public double Start { get; set; }
        public double End { get; set; }
        public double Rate { get; set; }

        public TankCalcState()
        {
			Abname = "NULL";
			Weight = 0d;
            Density = 0d;
            Inn = 0d;
            Volume = 0d;
            Full = 0d;
            LCG = 0d;
            TCG = 0d;
            VCG = 0d;
            Start = 0d;
            End = 0d;
            Rate = 0d;
        }
		public TankCalcState(string abname)
		{
			Abname = abname;
			Weight = 0d;
			Density = 0d;
			Inn = 0d;
			Volume = 0d;
			Full = 0d;
			LCG = 0d;
			TCG = 0d;
			VCG = 0d;
			Start = 0d;
			End = 0d;
			Rate = 0d;
		}

		void ModIVFWD(string tankname,string datatype,double value)
		{

			switch(datatype)
			{
				case "Full":
					SafeLoadAlgorithmService safeloadAlgorithm = SafeLoadAlgorithmService.GetInstance();
					string tankName = TankConstant.GetTankName(tankname);
					string inputstr = "{Manual}#{full}#{" + string.Join("#", tankName, value.ToString() + "#}");
					ManualCalcResult result = safeloadAlgorithm.CallPipeSingleCalc(inputstr, tankname);
					if (result != null)
					{
						//Tips：其余控件赋值来源于接口计算结果
						TankCalcState tankState = result.GetTankCalcState(tankName);
						Weight = tankState.Weight;
						Density = tankState.Density;
						Inn = tankState.Inn;
						Volume = tankState.Volume;
						LCG = tankState.LCG;
						TCG = tankState.TCG;
						VCG = tankState.VCG;
						Start = tankState.Start;
						End = tankState.End;
						Rate = tankState.Rate;
					}

					break;
				case "Volume":
					break ;
			}
		}
	}
}
